//
//  MyInvitePartMainViewController.m
//  StraightTrain
//
//  Created by mk on 15/12/7.
//  Copyright © 2015年 mk. All rights reserved.
//

#import "MyInvitePartMainViewController.h"

#import "BookingData.h"
#import "MyInviteCell.h"
#import "BookingDetailsViewController.h"

@interface MyInvitePartMainViewController ()
{
   BookingListData * bookingList;//等待预约列表

}

@end

@implementation MyInvitePartMainViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    titleLabel.text = @"预约列表";
    
    bookingList = [[BookingListData alloc]init];
    tableMain.refreshDelegate = self;
    [tableMain becomeRefreshing:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return bookingList.dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 140;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellTableIdentifier = @"MyInviteCellStr";
    
    MyInviteCell *cell = (MyInviteCell *)[tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
    if (!cell)
    {
        cell = (MyInviteCell *)[[[NSBundle mainBundle] loadNibNamed:@"MyInviteCell" owner:self options:nil] objectAtIndex:0];
    }
    [cell fillDateWith:[bookingList.dataArray objectAtIndex:indexPath.row]];
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    BookingInfoData * info = [bookingList.dataArray objectAtIndex:indexPath.row];
    BookingDetailsViewController * detail = [[BookingDetailsViewController alloc]initWithNibName:@"BookingDetailsViewController" bundle:nil];
    detail.strPatientId = info.booking_id;
    detail.detailsStatusCode = info.booking_statusCode;
    detail.isMySender = NO;
    //detail.strUrl = @"doctorpatientinfo";
    [self.navigationController pushViewController:detail animated:YES];
}


- (void)refreshTableViewDidTriggerRefresh:(RefreshTableView*)refreshTableView
{
    
    bookingList.urlPath = [NSString stringWithFormat:@"%@?username=%@&token=%@",[gProjConfig.dicAllUrl objectForKey:@"receiveBookingUrl"],[gProjConfig.dicUserData objectForKey:USER_tel],[gProjConfig.dicUserData objectForKey:USER_token]];
    bookingList.strDataKey = @"data";
    
    [bookingList getLoadData:^(AFHTTPRequestOperation *operation, id responseObject)
     {
        // bookingList.dataArray = [[NSMutableArray alloc]initWithCapacity:0];
         
         if (bookingList.dataArray.count > 0)
         {
             viewNo_Data.hidden = YES;
             self.view.backgroundColor = UIColorFromRGB(0xf0,0xf0,0xf0);
             [tableMain reloadData];
             
         }else
         {
             viewNo_Data.hidden = NO;
             self.view.backgroundColor = [UIColor whiteColor];
         }
         tableMain.backgroundColor = self.view.backgroundColor;
         [refreshTableView refreshFinished];
     } failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         [refreshTableView refreshFinished];
         HUDShowRequestError(error.domain, self.view)
     }];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
